<!DOCTYPE html>
<html>
<title>Tests that getElementById() API is exposed on DocumentFragment nodes</title>
<head>
<link rel="help" href="https://dom.spec.whatwg.org/#interface-nonelementparentnode">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<div id="notInFragment"></div>
<div id="duplicateId1"></div>
<script>
setup({single_test: true});

var fragment = new DocumentFragment();
var div = document.createElement("div");
div.id = "divID";
fragment.appendChild(div);
var a = document.createElement("a");
a.id = "aID";
div.appendChild(a);
var span = document.createElement("span");
span.id = "duplicateId1";
div.appendChild(span);
var h1 = document.createElement("h1");
h1.id = "duplicateId2";
div.appendChild(h1);
var h2 = document.createElement("h2");
h2.id = "duplicateId2";
div.appendChild(h2);

assert_equals(fragment.getElementById('divID'), div);
assert_equals(fragment.getElementById('aID'), a);
assert_equals(fragment.getElementById('notInFragment'), null);
assert_equals(fragment.getElementById('doesNotExist'), null);

// Duplicate ID cases.
assert_equals(fragment.getElementById('duplicateId1'), span); // Should return the Element *inside* the DocumentFragment.
assert_equals(fragment.getElementById('duplicateId2'), h1); // Should return the first matching Element in case of duplicate.
done();
</script>
</body>
</html>
